import { defineStore } from "pinia";
import { computed, reactive, ref, toRefs } from "vue";
import apis from '@/apis/index';

/**
 * 出勤统计-页面-共享数据仓库
 */
export const useDepartmentStore = defineStore("department", () => {
  const departmentListRef = ref([]);
  
  const isAttendanceLoadingRef = ref(true);
  /**
   * 响应式数据
   */
//   const attendanceData = reactive({
//     // 表格数据列表
//     tableList: [  
//       { title: '迟到详情', renderList: lateTableRef },
//       { title: '早退详情', renderList: earlyTableRef },
//     ],
//     // 图表数据列表
//     chartList: [
//       { title: '迟到员工数量', renderList: lateBIRef },
//       { title: '早退员工数量', renderList: earlyBIRef },
//     ]
//   });

  /**
   * 方法
   */
  // 更新数据
  async function updateState(data:any) {
    // earlyTableRef.value = data.earlyTable;
    // lateTableRef.value = data.lateTable;
    // earlyBIRef.value = data.earlyBI;
    // lateBIRef.value = data.lateBI;
    departmentListRef.value = data;
  }

  // 获取部门列表数据
  async function getDepartmentList() {
    try {
      const data = await apis.department.getDepartmentList_API();
      console.log(data,'department')
      if (data) {
        // 更新数据
        await updateState(data);
        console.log(departmentListRef,'department')
        // 修改加载状态
        setTimeout(() => {
          isAttendanceLoadingRef.value = false;
        }, 1500);
        
      }
    } catch (error) {
      console.log(error, 'pinia获取出勤统计数据失败');
      return;
    }
  }

  /**
   * 返回保留值
   */
  return {
    departmentListRef,
    getDepartmentList,
    isAttendanceLoadingRef,
  }
});